WGCNA.PCAandHeatmap <- function(tissue,Title){
  x <- tissue[apply(tissue,1,function(x) sum(x > 10) > (0.9*ncol(tissue))),]
  # 01.1.将readcount转换为logcpm
  y <- log10(edgeR::cpm(x)+1)
  y[1:4,1:4]
  # 01.2.将样品名称去掉生物学重复标记起到分组作用
  z <- gsub("_.*","",colnames(y))
  test <- as.data.frame(t(y))
  # 01.3.将分组标记放到表达矩阵最后一列
  dat <- cbind(test,z)
  # 02.1.准备PCA数据
  dat.pca <- PCA(dat[,-ncol(dat)], graph = F)
  # View(dat.pca)
  # 02.2.绘制PCA图并保存
  fviz_pca_ind(dat.pca,
               #geom.ind = "point",
               col.ind = dat$z,
               #palette = c("#9370DB", "#FF82AB", "#87CEFF", "#2E8B57", "#0000FF"),
               #addEllipses = T,
               legend.title = "Cultivar")
  ggsave(paste(Title,"SamplsPCAplot.pdf",sep = "_"), width = 8, height = 8)
  # 将每行表达量最大的前5000个基因拿出来做热图
  cg = names(tail(sort(apply(y, 1, function(x){sum(x)})),5000))
  # pheatmap(pheatmap(y[cg,],show_rownames = F,show_colnames = F),scale = "row")
  n=t(scale(t(y[cg,]))) # 'scale'可以对log-ratio数值进行归一化
  n[n>3]=3
  n[n< -3]= -3
  n[1:4,1:4]
  ac=data.frame(g=z)
  rownames(ac)=colnames(n) #把ac的行名给到n的列名，即对每一个探针标记上分组信息（是'noTNBC'还是'TNBC'）
  pheatmap(n,show_colnames =T,show_rownames = F,
           annotation_names_col = F,
           annotation_col=ac,
           filename = paste(Title,'heatmap_top5000.png',sep = "_"),
           clustering_distance_rows = "euclidean")
  assign("y",value = y, envir = globalenv())
}




